import request from "@/utils/request"

export interface QueryBigNormalListParams extends PaginationParams {
  /** 名称 */
  companyName?: string
  /** 登录账号 */
  loginPhone?: string
  /** 身份证/组织机构代码 */
  orgCode?: string
}

export enum BigNormalOrgType {
  身份证 = 0,
  组织机构代码 = 1,
}

export enum BigNormalStatus {
  启用 = 1,
  禁用 = 0,
}

export interface BigNormal {
  userId: string
  userImg: string
  nickname: string
  telephone: string
  balance: number
  status: BigNormalStatus
}

export async function queryList(params: QueryBigNormalListParams) {
  return request<BigNormal[]>('/app/manager/bigCompany/appUser/list', {
    data: params, token: localStorage.Authorization2
  })
}

export async function bindingUser(data: {
  telephone: string, 
  status: 1 | 2, // 1 绑定 2 解绑
}) {
  return request('/app/manager/bigCompany/appUser/bandOrNo', {
    data, token: localStorage.Authorization2
  })
}

export async function updateStatus(params: {id: string, status: BigNormalStatus}) {
  return request('/app/manager/bigCompany/status', {
    data: params, token: localStorage.Authorization2
  })
}

export async function getBigNormalDetail(params: {id: string}) {
  return request<BigNormal>('/app/manager/bigCompany/detail', {
    data: params, token: localStorage.Authorization2
  })
}

export async function editBigNormal(params: Partial<BigNormal>) {
  return request('/app/manager/bigCompany/addOrUp', {
    data: params, token: localStorage.Authorization2
  })
}

export async function resetPsw(params: {id: string}) {
  return request('/app/manager/bigCompany/resetPass', {
    data: params, token: localStorage.Authorization2
  })
}

export interface ChargeMoneyParams {
  userId: string
  amount: number
  commend?: string
}
export async function chargeMoney(params: ChargeMoneyParams) {
  return request('/app/manager/bigCompany/appUser/giveOrNo', {
    data: params, token: localStorage.Authorization2
  })
}

export async function getCompanyBalance() {
  return request<{balance: number}>('/app/manager/bigCompany/balance', {
    token: localStorage.Authorization2
  })
}
